
/**  
 * @Title: AsyMethod.java
 * @Package com.iflytek.uoamp.agent.core.asymethod
 * @Description: TODO(用一句话描述该文件做什么)
 * @author qinanyuan
 * @date 2017年4月5日 上午10:34:32
 * @version V1.0  
 */
    
package com.iflytek.uoamp.agent.core.agentclient.async;

import io.netty.channel.Channel;

import java.util.UUID;

import com.alibaba.fastjson.JSON;
import com.iflytek.uoamp.agent.core.sender.obj.RequestData;


/**
 * @ClassName: AsyMethod
 * @Description: 客户端异步发送方式
 * @author qinanyuan
 * @date 2017年4月5日 上午10:34:32
 */

public class AsyncWrite {
	public void writeAndAsync(final Channel channel, final RequestData request, final long timeout) throws Exception {

        if (channel == null) {
            throw new NullPointerException("channel");
        }
        if (request == null) {
            throw new NullPointerException("request");
        }
        if (timeout <= 0) {
            throw new IllegalArgumentException("timeout <= 0");
        }

        String requestId = UUID.randomUUID().toString();
        request.setRandomId(requestId);

        channel.writeAndFlush(JSON.toJSONString(request).getBytes("utf-8"));
    }
}
